/**
 * create by young (young2f@outlook.com) on 2023/4/15
 */
'use strict';

const dbs = require('./app/core/dbs');
const EventEmitter = require('events');
const eventBus = new EventEmitter();

const iiot = require('./app/smartIOT');

const configUtils = require('./app/utils/configUtils');

class AppBootHook {
    constructor(app) {
        this.app = app;
    }

    async configWillLoad() {
        this.app.EVENT_TOPIC_MQTT_ROOTER = 'EVENT_TOPIC_MQTT_ROOTER';
        this.app.dbs = new dbs(this.app);

        eventBus.setMaxListeners(this.app.config.dataBusMaxListeners);
        this.app.eventBus = eventBus;
        return configUtils.getSmartNodeConfig(this.app);
    }

    async didLoad() {
        return true;
    }

    async willReady() {
        return true;
    }

    async didReady() {

        /**
         * 应用已经启动完毕
         */
        return true;
    }

    async serverDidReady() {

        this.app.iiot = new iiot(this.app);
        return this.app.iiot.restart();
    }
}

module.exports = AppBootHook;
